import Cookies from 'js-cookie'

const TokenKey = 'vue_admin_template_token'
const timekey = `disseration`
const username = 'user_name'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

// 获取时间戳
export function getTimeStamp() {
  return Cookies.get(timekey)
}

// 设置时间戳
export function setTimeStamp() {
  Cookies.set(timekey, Date.now())
}

// 设置本地用户名
export function setLocalUsername(name) {
  localStorage.setItem(username, name)
}

// 获取本地用户名
export function getLocalUsername() {
  return { user_name: localStorage.getItem(username) }
}

// 删除本地用户名
export function removeLocalUsername() {
  localStorage.removeItem(username)
}

export function formatDate(date) {
  var date1 = new Date(date)
  var YY = date1.getFullYear() + '-'
  var MM = (date1.getMonth() + 1 < 10 ? '0' + (date1.getMonth() + 1) : date1.getMonth() + 1) + '-'
  var DD = (date1.getDate() < 10 ? '0' + (date1.getDate()) : date1.getDate())
  return YY + MM + DD
}

export function AfterDate(date) {
  var afterDate1 = new Date(date)
  var afterDate2 = afterDate1.setDate(afterDate1.getDate() + 7)
  var date1 = new Date(afterDate2)
  var YY = date1.getFullYear()
  var MM = (date1.getMonth() + 1 < 10 ? '0' + (date1.getMonth() + 1) : date1.getMonth() + 1)
  var DD = (date1.getDate() < 10 ? '0' + (date1.getDate()) : date1.getDate())
  return `${YY}-${MM}-${DD}`
}
